
#if !defined(AFX_CALENDARCTRL_H__9CAF29B3_2548_445C_9333_D7D0AE9B4526__INCLUDED_)
#define AFX_CALENDARCTRL_H__9CAF29B3_2548_445C_9333_D7D0AE9B4526__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CalendarCtrl.h : header file
//
#include "BitmapButtonEx.h"
/////////////////////////////////////////////////////////////////////////////
// CCalendarCtrl window

#define DATE_ITEM_CUR_MONTH		1
#define DATE_ITEM_ENABLED		2
#define DATE_ITEM_SELECTED		4
#define DATE_ITEM_CUR_DAY		8

#define DATE_ITEM_OUT_RANGE		128

class CCalendarCtrl;
class CCalendarOwner
{
public:
	CCalendarOwner(CWnd* pWnd) : m_pWnd(pWnd){}
	inline CWnd* GetWindow() const{return m_pWnd;}
	virtual void OnSelectedDateChanged(COleDateTime dtCurSelectedDate) = 0;
	virtual void OnMonthChanged(CCalendarCtrl* pCalendar) = 0;
	virtual BOOL OnDetermineDateState(COleDateTime dtDateItem) = 0;
private:
	CWnd* m_pWnd;
};

class CCalendarCtrl : public CWnd, public CAppearanceClient
{
public:
	CCalendarCtrl();
	virtual ~CCalendarCtrl();

	BOOL Create(const RECT& rect, CCalendarOwner* pOwner, UINT nID);

	void UpdateState();
	BOOL SelectDate(int nYear, int nMonth, int nDay);
	BOOL SelectMonth(int nYear, int nMonth);
	BOOL GetSelectedDate(COleDateTime& dtDateTime);

	inline int GetCurYear() const{
		return m_nCurYear;
	}
	inline int GetCurMonth() const{
		return (m_nCurMonth+1);
	}

protected:
	//{{AFX_MSG(CCalendarCtrl)
	afx_msg void OnPaint();
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnBtnPrevMonth();
	afx_msg void OnBtnNextMonth();
	afx_msg void OnBtnPrevYear();
	afx_msg void OnBtnNextYear();
	afx_msg void OnEnable(BOOL bEnable);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

	virtual void OnSkinChanged();
	virtual void OnLanguageChanged();
	virtual void RepositionChildWindows();

private:

	struct DateItem
	{
		CRect rectItem;
		DWORD dwState;
		COleDateTime Date;
	};

	CCalendarOwner* m_pCalendarOwner;

	COLORREF m_clrBkgnd;
	COLORREF m_clrWeekText;
	COLORREF m_clrHeadText;

	COLORREF m_clrNormalText;
	COLORREF m_clrNonCurMonthText;
	COLORREF m_clrCurDayText;
	COLORREF m_clrEnabledBkgnd;
	COLORREF m_clrEnabledSelectedBkgnd;
	COLORREF m_clrDisabledSelectedBkgnd;

	CFont m_fntHeadText;
	CFont m_fntWeekdayText;
	CFont m_fntDaytext;

	CBitmapButtonEx m_btnPrevMonth;
	CBitmapButtonEx m_btnNextMonth;
	CBitmapButtonEx m_btnPrevYear;
	CBitmapButtonEx m_btnNextYear;
	CBitmapEx m_bmpHeadBar;
	CBitmapEx m_bmpWeekdayBar;

	int m_nCurYear;
	int m_nCurMonth;	//0~11
	int m_nSelectedDateIndex;

	CString m_strWeekday[7];
	CString m_strDateFormat;
	COleDateTime m_dtSelectedDate;
	DateItem m_DateItem[42];

	void GetPartsRect(CRect& rectHeadBar, CRect& rectWeekBar, CRect& rectDatePanel, const CRect& rectCalendar);

	void DrawHeadBar(CDC* pDC, const CRect& rectHeadBar);
	void DrawWeekBar(CDC* pDC, const CRect& rectWeekBar);
	void DrawDatePanel(CDC* pDC, const CRect& rectDatePanel);

	void CalcDateItemsRect(const CRect& rectDatePanel);
	void UpdateDateItems();

	int HitTest(const CPoint& point);
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CALENDARCTRL_H__9CAF29B3_2548_445C_9333_D7D0AE9B4526__INCLUDED_)
